//引入第三层函数
const { getCar3, getCarDetail3, searchCars3, add3, upDate3 ,userSearch3,upDateRemoved3} = require("../database/dao/car.js")

//暴露第二层函数
module.exports = {
    getCars2,
    getCarDetail2,
    searchCars2,
    add2,
    upDate2,
    upDateRemoved2
}

//分页获取数据
async function getCars2(data) {
    // console.log("第二层" + data);

    const result = await getCar3(data)
    if (result.message.length > 0) {
        return result
    } else {
        return "未找到相关数据"
    }
}

//获取车辆详细数据
async function getCarDetail2(data) {
    // console.log("第二层" + data);

    const result = await getCarDetail3(data)
    if (result.length > 0) {
        return result
    } else {
        return "未找到相关数据"
    }
}

//搜索车辆
async function searchCars2({ selectedType, selectedValue, userId }) {
    let result;
    if (userId == null) {
        result = await searchCars3({selectedType,selectedValue})
    }else{
        result=await userSearch3({userId})
    }

    if (result.message.length) {
        return result
    } else {
        return "未找到相关数据"
    }
}
//新增车辆
async function add2(data) {
    const result = await add3(data);
    if (result) {
        return result
    } else {
        return "新增失败"
    }
}

//修改状态
async function upDate2(data) {
    // console.log("第二层" + data);

    const result = await upDate3(data);
    if (result.ok === 1) {
        return true
    } else {
        return false
    }
}

//下架车辆
async function upDateRemoved2(data){
    const result=await upDateRemoved3(data)
    if(result.ok===1){
        return true
    }else{
        return false
    }
}